package com.usian.controller;

import com.usian.model.admin.dtos.NewsAuthDto;
import com.usian.model.common.dtos.PageResponseResult;
import com.usian.model.common.dtos.ResponseResult;
import com.usian.model.media.dtos.WmNewsDto;
import com.usian.model.media.dtos.WmNewsPageReqDto;
import com.usian.model.media.pojos.WmNews;
import com.usian.model.media.pojos.WmUser;
import com.usian.service.WmNewsService;
import com.usian.wemedia.WmNewsControllerApi;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/v1/news")
public class WmNewsController implements WmNewsControllerApi {

    @Autowired
    private WmNewsService wmNewsService;

    @PostMapping("/list")
    @Override
    public ResponseResult findList(@RequestBody WmNewsPageReqDto dto) {
        return wmNewsService.findList(dto);
    }

    @Override
    @PostMapping("/submit")
    public ResponseResult saveNews(@RequestBody WmNewsDto dto) {
        //return wmNewsService.saveNews(dto,dto.getType());
        if(dto.getStatus().equals(0)){
            ResponseResult responseResult = wmNewsService.saveNews(dto, (short) 0);
            return responseResult;
        }else{
            ResponseResult responseResult = wmNewsService.saveNews(dto, (short) 1);
            return responseResult;
        }
    }

    @Override
    @GetMapping("/one/{id}")
    public ResponseResult findById(@PathVariable("id") Integer id) {
        return wmNewsService.findById(id);
    }

    @GetMapping("/del_news/{id}")
    @Override
    public ResponseResult delNews(@PathVariable("id") Integer id) {
        return wmNewsService.delNews(id);
    }

    @Override
    @PostMapping("/down_or_up")
    public ResponseResult downOrUp(@RequestBody WmNewsDto dto) {
        return wmNewsService.downOrUp(dto);
    }

    /**
     * feign远程调用 根据文章id查询文章详情
     *
     * @param id
     * @return
     */
    @Override
    @GetMapping("/findByNewId/{id}")
    public WmNews findByNewId(@PathVariable("id") Integer id) {
        return wmNewsService.findByNewId(id);

    }

    /**
     * feign 更新文章审核状态
     * @param wmNews
     * @return
     */
    @Override
    @PostMapping("/updateNews")
    public boolean updateNews(@RequestBody WmNews wmNews) {
        return wmNewsService.updateNews(wmNews);
    }

    /**
     * feign 更具登录用户查询用户信息
     *
     * @param id
     * @return
     */
    @Override
    @GetMapping("/findByUserId/{id}")
    public WmUser findByUserId(@PathVariable("id") Integer id) {
        return wmNewsService.findByUserId(id);
    }

    /**
     * 查询 审核通过待发布文章列表
     *
     * @return
     */
    @Override
    @PostMapping("/findWmnews")
    public List<Integer> findWmnews() {
        return wmNewsService.findWmnews();
    }

    /**
     * 查询人工审核列表
     *
     * @param dto
     * @return
     */
    @Override
    @PostMapping("/findList")
    public PageResponseResult findListRengong(@RequestBody NewsAuthDto dto) {
        return wmNewsService.findListRengong(dto);
    }

    /**
     * 查询人工审核详情
     *
     * @param id
     * @return
     */
    @Override
    @GetMapping("/findDetail/{id}")
    public WmNews findDetail(@PathVariable("id") Integer id) {
        return wmNewsService.findDetail(id);
    }

    /**
     * 审核通过、失败
     *
     * @param dto
     * @param type
     * @return
     */
    @Override
    @PostMapping("/auth")
    public ResponseResult auth(@RequestBody NewsAuthDto dto,@RequestParam int type) {
        return wmNewsService.auth(dto,type);
    }
}
